Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Collections.​Generic.​Stack<​T>

Assembly: System.Collections

Inheritance: object → Stack

Implemented Interfaces

Represents a variable size last-in-first-out (LIFO) collection of instances of the same specified type.

Properties

public int
Count
Gets the number of elements contained in the <see cref="T:System.Collections.Generic.Stack`1" /> .
public int
Capacity
Gets the total numbers of elements the internal data structure can hold without resizing.

Methods

public void
Clear​()
Removes all objects from the <see cref="T:System.Collections.Generic.Stack`1" /> .
public bool
Contains​(T item)
Determines whether an element is in the <see cref="T:System.Collections.Generic.Stack`1" /> .
Returns <see langword="true" /> if <paramref name="item" /> is found in the <see cref="T:System.Collections.Generic.Stack`1" /> ; otherwise, <see langword="false" /> .
item The object to locate in the <see cref="T:System.Collections.Generic.Stack`1" /> . The value can be <see langword="null" /> for reference types.
public void
CopyTo​(T[] array, int arrayIndex)
Copies the <see cref="T:System.Collections.Generic.Stack`1" /> to an existing one-dimensional <see cref="T:System.Array" /> , starting at the specified array index.
array The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.Stack`1" /> . The <see cref="T:System.Array" /> must have zero-based indexing.
arrayIndex The zero-based index in <paramref name="array" /> at which copying begins.
public Enumerator<​T>
GetEnumerator​()
Returns an enumerator for the <see cref="T:System.Collections.Generic.Stack`1" /> .
Returns An <see cref="T:System.Collections.Generic.Stack`1.Enumerator" /> for the <see cref="T:System.Collections.Generic.Stack`1" /> .
public T
Peek​()
Returns the object at the top of the <see cref="T:System.Collections.Generic.Stack`1" /> without removing it.
Returns The object at the top of the <see cref="T:System.Collections.Generic.Stack`1" /> .
public T
Pop​()
Removes and returns the object at the top of the <see cref="T:System.Collections.Generic.Stack`1" /> .
Returns The object removed from the top of the <see cref="T:System.Collections.Generic.Stack`1" /> .
public void
Push​(T item)
Inserts an object at the top of the <see cref="T:System.Collections.Generic.Stack`1" /> .
item The object to push onto the <see cref="T:System.Collections.Generic.Stack`1" /> . The value can be <see langword="null" /> for reference types.
public int
EnsureCapacity​(int capacity)
Ensures that the capacity of this Stack is at least the specified <paramref name="capacity" /> . If the current capacity is less than <paramref name="capacity" /> , it is increased to at least the specified <paramref name="capacity" /> .
Returns The new capacity of this stack.
capacity The minimum capacity to ensure.
public T[]
ToArray​()
Copies the <see cref="T:System.Collections.Generic.Stack`1" /> to a new array.
Returns A new array containing copies of the elements of the <see cref="T:System.Collections.Generic.Stack`1" /> .
public void
TrimExcess​()
Sets the capacity to the actual number of elements in the <see cref="T:System.Collections.Generic.Stack`1" /> , if that number is less than 90 percent of current capacity.
public void
TrimExcess​(int capacity)
Sets the capacity of a <see cref="T:System.Collections.Generic.Stack`1" /> object to a specified number of entries.
capacity The new capacity.
public bool
TryPeek​(T& result)
public bool
TryPop​(T& result)
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object